namespace cnVery.bbs.UI.Forum
{
    using cnVery.bbs.Kernel;
    using cnVery.Controls;
    using cnVery.Utils;
    using System;
    using System.Data;
    using System.Web.UI.WebControls;

    public class quote : Main
    {
        private string filter;
        protected Repeater list;
        private int loops;
        private string path;
        private string sort;
        private int textlength;

        public quote()
        {
            this.textlength = this.IsNumeric(this.Get("textlength")) ? int.Parse(this.Get("textlength")) : 30;
            this.loops = this.IsNumeric(this.Get("loops")) ? int.Parse(this.Get("loops")) : 10;
            this.sort = (this.Get("sort") == "hot") ? "replies" : "id";
            this.path = (this.Get("path") == string.Empty) ? (this.currentPath + "/") : this.Get("path");
            this.filter = " where isdelete=0 ";
            string str = this.Get("boards", CheckGetEnum.Safety);
            if (((str != "-1") && (str != "")) && (str != null))
            {
                this.filter = this.filter + "and boardid in (" + str + ")";
            }
        }

        private void InitializeComponent()
        {
            base.Load += new EventHandler(this.Page_Load);
            this.list.ItemCreated += new RepeaterItemEventHandler(this.Roll);
        }

        protected override void OnInit(EventArgs e)
        {
            this.InitializeComponent();
            base.OnInit(e);
        }

        private void Page_Load(object sender, EventArgs e)
        {
            string sql = string.Concat(new object[] { "select top ", this.loops, " id, title, addtime, replies from bbs_topic ", this.filter, " order by ", this.sort, " desc" });
            if (this.sort != "id")
            {
                sql = sql + ", id desc";
            }
            this.list.DataSource = base.conn.GetDataTable(sql);
            this.list.DataBind();
            base.conn.Close();
        }

        private void Roll(object sender, RepeaterItemEventArgs e)
        {
            DataRowView dataRowViewFromRepeaterItemEventArgs = this.GetDataRowViewFromRepeaterItemEventArgs(e);
            if (dataRowViewFromRepeaterItemEventArgs != null)
            {
                Anchor anchor = (Anchor) e.Item.FindControl("anchor");
                Span span = (Span) e.Item.FindControl("replies");
                Span span2 = (Span) e.Item.FindControl("addtime");
                anchor.Href = this.path + "topic.aspx?topicid=" + dataRowViewFromRepeaterItemEventArgs["id"];
                anchor.Text = this.Left(dataRowViewFromRepeaterItemEventArgs["title"], this.textlength).Replace("\"", "\\\"");
                span.Text = ((int) dataRowViewFromRepeaterItemEventArgs["replies"]).ToString();
                string format = span2.Attributes.Get("FormatProvider");
                switch (format)
                {
                    case "":
                    case null:
                        format = "M-d";
                        break;
                }
                span2.Text = ((DateTime) dataRowViewFromRepeaterItemEventArgs["addtime"]).ToString(format);
            }
        }
    }
}

